/**
 * Created by Dell on 2016/12/16 0016.
 */

import org.geotools.data.shapefile.shp.ShapefileException;
import org.neo4j.gis.spatial.ShapefileImporter;
import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.graphdb.factory.GraphDatabaseFactory;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.charset.Charset;

public class importShapefiletest {
    /**
     * @param args
     * import shapefile to neo4j database
     * just Extract from the org.neo4j.gis.spatial.testfordoc
     */
    private String databasepath = "d://database/learn1";

    public void importShapfile() throws ShapefileException, FileNotFoundException, IOException {
        System.out.println("\n=== Test Import Shapefile ===");

        GraphDatabaseService graphdb = new GraphDatabaseFactory()
                .newEmbeddedDatabaseBuilder(new File(databasepath))
                .loadPropertiesFromFile(Learn1.class.getResource("/").getPath() + "neo4j.properties")
                .newGraphDatabase();
        try {
            ShapefileImporter shpImporter = new ShapefileImporter(graphdb);
            shpImporter.importFile("D:\\testShp\\shenzen.shp", "shenzen", Charset.forName("UTF-8"));
        } finally {
            graphdb.shutdown();
        }
    }

    public static void main(String[] args) throws ShapefileException, FileNotFoundException, IOException {
        // TODO Auto-generated method stub
        importShapefiletest isf = new importShapefiletest();
        isf.importShapfile();
    }

}
